package apple.encryptedNode.activities;

import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import apple.encryptedNode.dao.OperationDAO;
import apple.encryptedNote.tools.SMSService;

/**
 * 
 * 短信拦截广播
 * **/
public class DecryptoSMS extends BroadcastReceiver {
	private OperationDAO operationDAO;
	private static final String DES = null;
	private static final String tag = DecryptoSMS.class.getName();

	
	
	@Override
	public void onReceive(Context context, Intent intent) {
		Log.d(tag, "onReceive");
		Toast.makeText(context, "DecryptoSMS->DecryptoSMS", Toast.LENGTH_LONG)
				.show();
		operationDAO=new OperationDAO(context);
		if ("android.provider.Telephony.SMS_RECEIVED"
				.equals(intent.getAction())) {
			Bundle bundle = intent.getExtras();

			Object[] pdus = (Object[]) bundle.get("pdus");
			
			SMSService sms=new SMSService(context);
		    List<String> duanxin= 	sms.jiemi3(pdus);//解密短信
		    if(duanxin.size()>0)
		    {
		    	Log.d(tag, "save sms!");
		    	Log.d(tag, "save sms!"+duanxin.get(1));
		    	operationDAO.save(duanxin.get(0)+" sms", duanxin.get(1), "", "n");//保存拦截短信，get(0)：电话号码，1为短信内容
		    }
			
		}
	}

}
